{createAction} = require('redux-actions')

actions =
  getListStart:createAction('BWSS/GET_LIST_START')
  getListCompleted:createAction('BWSS/GET_LIST_COMPLETED')
  refreshListStart:createAction('BWSS/REFRESH_LIST_START')
  refreshListCompleted:createAction('BWSS/REFRESH_LIST_COMPLETED')
  fetchRefreshList:()->
    (dispatch)->
      debugger
      dispatch actions.refreshListStart()
      str = "http://202.136.214.173/api/v_berth?state=getAll"
      fetch(str,{
          method: 'GET'
          mode: 'cors'
          cache: 'default'
          headers: { 'Content-Type':'application/x-www-form-urlencoded'}
          # body:"pageNum=#{pageNum}&state=1"
        })
      .then (res)->
        res.json()
      .then (json)->
        date = new Date()
        dispatch actions.refreshListCompleted
          list:json
          lastFetchTime:date
      .catch (err)->
        console.log(err)


  # fetchGetList:(pageNum)->
  #   (dispatch)->
  #     debugger
  #     dispatch actions.getListStart()
  #     str = "http://202.136.214.173/api/v_berth?pageNum=#{pageNum}"
  #     fetch(str,{
  #         method: 'GET'
  #         mode: 'cors'
  #         cache: 'default'
  #         headers: { 'Content-Type':'application/x-www-form-urlencoded'}
  #         # body:"pageNum=#{pageNum}&state=1"
  #       })
  #     .then (res)->
  #       res.json()
  #     .then (json)->
  #       date = new Date()
  #       dispatch actions.getListCompleted
  #         list:json
  #         lastFetchTime:date
  #     .catch (err)->
  #       console.log(err)

module.exports = actions




# fetchGetList : (pageNum)->
#   (dispatch)->
#     # fetch('http://202.136.214.173/api/V_SHORT_INPLAN?pageNum=1&state=1'
#     dispatch(getInPlanListStart())
#     $.get 'http://202.136.214.173/api/V_SHORT_INATTEMP',{pageNum:pageNum,state:1},(data)->
#       if(pageNum is 1)
#         dispatch getRefreshList(data)
#       else
#         dispatch getInPlanList(data)
